/*
 * utf8stringobject.h
 *
 *  Created on: Oct 27, 2009
 *  Author: Silviu Caragea
 */

#ifndef UTF8STRINGOBJECT_H_
#define UTF8STRINGOBJECT_H_

#include "stringobject.h"

namespace templatipus {

class TUtf8StringObject: public TStringObject {

public:
	template<typename T> static void internalNumberToString(
			std::string & buffer, utf8Ptr strFormat, const T value);

	//constructor && destructor

	TUtf8StringObject();
	TUtf8StringObject(const TemplateObject &other);
	TUtf8StringObject(const tbool &rhs);
	TUtf8StringObject(const int8 &rhs);
	TUtf8StringObject(const int16 &rhs);
	TUtf8StringObject(const int32 &rhs);
	TUtf8StringObject(const int64 &rhs);
	TUtf8StringObject(const float32 &rhs);
	TUtf8StringObject(const float64 &rhs);
	TUtf8StringObject(const std::wstring& rhs);
	TUtf8StringObject(const std::string& rhs);
	TUtf8StringObject(const utf8Ptr &rhs);
	TUtf8StringObject(const unicodePtr &rhs);

	virtual ~TUtf8StringObject();

	//base methods
	virtual TObjectType getType() const;

	//operations

	virtual TUtf8StringObject operator +(const TemplateObject &other);
	virtual const TemplateObject& operator +=(const TemplateObject &other);

	//assigning values
	virtual TemplateObject& operator=(const TemplateObject &other);
	virtual TemplateObject& operator=(const int8 &other);
	virtual TemplateObject& operator=(const int16 &other);
	virtual TemplateObject& operator=(const int32 &other);
	virtual TemplateObject& operator=(const int64 &other);
	virtual TemplateObject& operator=(const float32 &other);
	virtual TemplateObject& operator=(const float64 &other);
	virtual TemplateObject& operator=(const std::wstring& other);
	virtual TemplateObject& operator=(const std::string& other);
	virtual TemplateObject& operator=(const utf8Ptr other);
	virtual TemplateObject& operator=(const unicodePtr other);

	//conversions to number
	virtual tbool toBool() const;
	virtual int8 toInt8() const;
	virtual uint8 toUint8() const;
	virtual int16 toInt16() const;
	virtual uint16 toUint16() const;
	virtual int32 toInt32() const;
	virtual uint32 toUint32() const;
	virtual int64 toInt64() const;
	virtual uint64 toUint64() const;
	virtual float32 toFloat32() const;
	virtual float64 toFloat64() const;

	//conversion to string
	virtual std::string toString() const;
	virtual std::wstring toWString() const;

	//inner operators

	virtual utf8c operator [](const uint32 index);

	//methods comparison
	virtual tbool equals(const TemplateObject &other) const;
	virtual tbool notEquals(const TemplateObject &other) const;
	virtual tbool greater(const TemplateObject &other) const;
	virtual tbool less(const TemplateObject &other) const;
	virtual tbool greaterOrEquals(const TemplateObject &other) const;
	virtual tbool lessOrEquals(const TemplateObject &other) const;

	//class stuff
	uint32 getLength();
	utf8c characterAtIndex(uint32 index);

	//operation
	void appendString(TStringObject &object);
	void appendUint8(uint8 nr);
	void appendInt16(int16 nr);
	void appendUint16(uint16 nr);
	void appendInt32(int32 nr);
	void appendUint32(uint32 nr);
	void appendInt64(int64 nr);
	void appendUint64(uint64 nr);
	void appendUtf8Ptr(utf8Ptr ptr);
	void appendString(std::string &str);

	virtual TemplateObject * newInstance() const {
		return new TUtf8StringObject();
	}

protected:
	std::string internalBuffer;

};

}

#endif /* UTF8STRINGOBJECT_H_ */
